package com.sjgtw.cloud.web.path.controller;

import com.sjgtw.cloud.common.core.utils.poi.ExcelUtil;
import com.sjgtw.cloud.common.core.web.controller.BaseController;
import com.sjgtw.cloud.common.core.web.domain.AjaxResult;
import com.sjgtw.cloud.common.core.web.page.TableDataInfo;
import com.sjgtw.cloud.web.path.domain.UpperLocation;
import com.sjgtw.cloud.web.path.dto.UpperLocationDTO;
import com.sjgtw.cloud.web.path.service.IEmergencyPathService;
import com.sjgtw.cloud.web.path.service.IPathPointService;
import com.sjgtw.cloud.web.path.service.IUpperLocationService;
import com.sjgtw.cloud.web.path.vo.UpperLocationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 上道地点Controller
 * 
 * @author lvyoufang
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/upperLocation")
@Api(tags = "5.1、应急路径")
public class UpperLocationController extends BaseController
{
    @Autowired
    private IUpperLocationService upperLocationService;
    @Autowired
    private IEmergencyPathService emergencyPathService;
    @Autowired
    private IPathPointService pathPointService;

    /**
     * 查询上道地点列表
     */
    @ApiOperation(value = "查询上道地点列表")
    @GetMapping("/list")
    public TableDataInfo list(UpperLocationDTO upperLocation)
    {
        startPage();
        List<UpperLocation> list = upperLocationService.selectUpperLocationList(upperLocation);
        return getDataTable(list);
    }

    /**
     * 导出上道地点列表
     */
    @ApiOperation(value = "导出上道地点列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, UpperLocationDTO upperLocation)
    {
        List<UpperLocation> list = upperLocationService.selectUpperLocationList(upperLocation);
        ExcelUtil<UpperLocation> util = new ExcelUtil<UpperLocation>(UpperLocation.class);
	    try {
		    util.exportExcel(response, list, "上道地点数据");
	    } catch (IOException e) {
		    e.printStackTrace();
	    }
    }

    /**
     * 获取上道地点详细信息
     */
    @ApiOperation(value = "获取上道地点详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(upperLocationService.selectUpperLocationById(id));
    }

    /**
     * 新增上道地点
     */
    @ApiOperation(value = "新增上道地点")
    @PostMapping
    public AjaxResult add(@RequestBody UpperLocation upperLocation)
    {
        return toAjax(upperLocationService.insertUpperLocation(upperLocation));
    }

    /**
     * 修改上道地点
     */
    @ApiOperation(value = "修改上道地点")
    @PutMapping
    public AjaxResult edit(@RequestBody UpperLocationVO upperLocationVO)
    {
        return toAjax(upperLocationService.updateUpperLocation(upperLocationVO));
    }

    /**
     * 删除上道地点
     */
   /* @ApiOperation(value = "删除上道地点")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(upperLocationService.deleteUpperLocationByIds(ids));
    }*/
    /**
     * 删除上道地点
     */
    @ApiOperation(value = "删除上道地点")
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(upperLocationService.deleteUpperLocationById(id));
    }

//    /**
//     * 删除应急路径
//     */
//    @ApiOperation(value = "删除应急路径")
//	@DeleteMapping("/{id}")
//    public AjaxResult removePath(@PathVariable Long id)
//    {
//        pathPointService.deleteByPathId(id);
//        return toAjax(emergencyPathService.deleteEmergencyPathById(id));
//    }
}
